/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelWszystkieWarstwy.java
 *
 * Created on 2011-05-14, 11:26:00
 */

package App.widoki;

import App.kontrolery.IObslugaWyboruWarstwy;
import javax.swing.JLabel;
import skladowisko.Pole;

/**
 *
 * @author Krzysiek
 */
public class PanelWszystkieWarstwy extends javax.swing.JPanel {

    /** Creates new form PanelWszystkieWarstwy */
    private Pole pole;

    private int rozmiarWX;
    private int rozmiarWY;
    private int warstwy;

    private final int separator = 1;
    private IObslugaWyboruWarstwy nadzorca = null;

    public PanelWszystkieWarstwy(Pole pole, int width, int height, IObslugaWyboruWarstwy nadzorca)
    {
        initComponents();
        this.pole = pole;
        this.setBounds(10, 10, width-20, height-20);
        this.nadzorca = nadzorca;

        dodajWszystkieWarstwy();
    }

    private void dodajWszystkieWarstwy()
    {
        obliczParametry();

        for(int i=warstwy;i>0;i--)
        {
            int x = 10;
            int y = 10 + (warstwy-i)*(rozmiarWY+separator);

            PanelWarstwa nWarstwa = new PanelWarstwa(pole.getZawartoscPola().getWarstwa(i));
            nWarstwa.setBounds(x, y, rozmiarWX, rozmiarWY);
            nWarstwa.ustawNadzorce(nadzorca);

            JLabel etykieta = new JLabel(""+i);
            etykieta.setBounds(x-8, y+3, 20, 20);
            
            this.add(nWarstwa);
            this.add(etykieta);
        }

        this.validate();
        this.repaint();
    }

    private void obliczParametry()
    {
        warstwy = pole.getZawartoscPola().getLiczbaWarstwa();

        rozmiarWX = this.getWidth()-20;
        rozmiarWY = (this.getHeight()-20-(warstwy*separator))/warstwy;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(204, 204, 255));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 260, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents




    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
